package com.haixiaoke.saas.manage.lock.controller;

import java.util.List;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.lock.domain.DeviceLock;
import com.haixiaoke.saas.lock.service.IDeviceLockService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备锁Controller
 * 
 * @author panda
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/manage/lock/lock")
public class ManageDeviceLockController extends BaseController {
    @Autowired
    private IDeviceLockService deviceLockService;

    /**
     * 查询设备锁列表
     */
    @PreAuthorize("@ss.hasPermi('manage:lock:page')")
    @GetMapping("/page")
    public TableDataInfo page(DeviceLock deviceLock) {
        startPage();
        List<DeviceLock> list = deviceLockService.selectDeviceLockList(deviceLock);
        return getDataTable(list);
    }

    /**
     * 获取锁型号列表
     */
    @GetMapping("/model/list")
    public AjaxResult modelList() {
        return success(deviceLockService.modelList().getJSONArray("data"));
    }

    /**
     * 获取设备锁详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:lock:query')")
    @GetMapping(value = "/{lockId}")
    public AjaxResult getInfo(@PathVariable("lockId") Long lockId) {
        return success(deviceLockService.selectDeviceLockByLockId(lockId));
    }

    /**
     * 新增设备锁
     */
    @PreAuthorize("@ss.hasPermi('manage:lock:add')")
    @Log(title = "设备锁", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceLock deviceLock) {
        deviceLock.setCreateBy(getUsername());
        return deviceLockService.manageInsertDeviceLock(deviceLock);
    }

    /**
     * 删除设备锁
     */
    @PreAuthorize("@ss.hasPermi('manage:lock:remove')")
    @Log(title = "设备锁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lockId}")
    public AjaxResult remove(@PathVariable Long lockId) {
        return deviceLockService.deleteDeviceLockByLockId(lockId);
    }
}
